#pragma once
#include <iostream>
#include "Protocol.hpp"
enum Errocode
{
    success = 0,
    Diverro,
    Moderro,
    Unknow
};

class Calcute
{
public:
    Calcute()
    {
    }
    std::shared_ptr<Protocal::Reponse> Cal(std::shared_ptr<Protocal::Request> req)
    {
        std::shared_ptr<Protocal::Reponse> reqs = factor.BuildRespose();
        switch (req->Get_oper())
        {
        case '+':
            reqs->Setresult(req->Getdata_x() + req->Getdata_y());
            break;
        case '-':
            reqs->Setresult(req->Getdata_x() - req->Getdata_y());
            break;
        case '*':
            reqs->Setresult(req->Getdata_x() * req->Getdata_y());
            break;
        case '/':
        {   
            if(req->Getdata_y()==0)
            {
                reqs->SetCode(Diverro);
            } 
            else
            {
                reqs->Setresult(req->Getdata_x() / req->Getdata_y());
            }
            break;
        }
        case '%':
        {   
            if(req->Getdata_y()==0)
            {
                reqs->SetCode(Moderro);
            } 
            else
            {
                reqs->Setresult(req->Getdata_x() % req->Getdata_y());
            }
        }
            break;
        default:
            reqs->SetCode(Unknow);
            break;
        }
        return reqs;
    }
    ~Calcute()
    {
    }

private:
    Protocal::Factory factor;
};